﻿//--------------------------------------------------------------------------------------------------------------------------------
// <copyright file="RectangularGrid2D.LocationInGrid.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>Exul</author>
//--------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.FiniteElementMethod
{
    using System;

    /// <content>Describes location of an element in the two-dimensional rectangular grid.</content>
    public partial class RectangularGrid2D
    {
        /// <summary>Represents location of an element in the two-dimensional rectangular grid.</summary>
        public sealed class LocationInGrid
        {
            /// <summary>Initializes a new instance of the <see cref="LocationInGrid"/> class.</summary>
            /// <param name="leftBorderPointIndex">The index of left border point.</param>
            /// <param name="rightBorderPointIndex">The index of right border point.</param>
            /// <param name="bottomBorderPointIndex">The index of bottom border point.</param>
            /// <param name="topBorderPointIndex">The index of top border point.</param>
            /// <exception cref="ArgumentOutOfRangeException">
            ///     <paramref name="leftBorderPointIndex"/>, <paramref name="rightBorderPointIndex"/>,
            ///     <paramref name="bottomBorderPointIndex"/> or <paramref name="topBorderPointIndex"/> is negative.
            ///     <para>--or--</para>
            ///     <para>
            ///         <paramref name="rightBorderPointIndex"/> is less than <paramref name="leftBorderPointIndex"/>.
            ///     </para>
            ///     <para>--or--</para>
            ///     <para>
            ///         <paramref name="topBorderPointIndex"/> is less than <paramref name="bottomBorderPointIndex"/>.
            ///     </para>
            /// </exception>
            public LocationInGrid(
                int leftBorderPointIndex, int rightBorderPointIndex, int bottomBorderPointIndex, int topBorderPointIndex)
            {
                #if SAFE

                if (leftBorderPointIndex < 0)
                {
                    throw ThrowHelper.PointIndexIsNegative("leftBorderPointIndex", leftBorderPointIndex);
                }

                if (rightBorderPointIndex < 0)
                {
                    throw ThrowHelper.PointIndexIsNegative("rightBorderPointIndex", rightBorderPointIndex);
                }

                if (bottomBorderPointIndex < 0)
                {
                    throw ThrowHelper.PointIndexIsNegative("bottomBorderPointIndex", bottomBorderPointIndex);
                }

                if (topBorderPointIndex < 0)
                {
                    throw ThrowHelper.PointIndexIsNegative("topBorderPointIndex", topBorderPointIndex);
                }

                if (rightBorderPointIndex < leftBorderPointIndex)
                {
                    throw ThrowHelper.InvalidLocationInGrid(
                        "leftBorderPointIndex", leftBorderPointIndex, "rightBorderPointIndex", rightBorderPointIndex);
                }

                if (topBorderPointIndex < bottomBorderPointIndex)
                {
                    throw ThrowHelper.InvalidLocationInGrid(
                        "bottomBorderPointIndex", bottomBorderPointIndex, "topBorderPointIndex", topBorderPointIndex);
                }

                #endif

                this.LeftBorderPointIndex = leftBorderPointIndex;
                this.RightBorderPointIndex = rightBorderPointIndex;
                this.BottomBorderPointIndex = bottomBorderPointIndex;
                this.TopBorderPointIndex = topBorderPointIndex;
            }

            /// <summary>Gets the index of left border point.</summary>
            /// <value>The index of left border point.</value>
            public int LeftBorderPointIndex
            {
                get;
                private set;
            }

            /// <summary>Gets the index of right border point.</summary>
            /// <value>The index of right border point.</value>
            public int RightBorderPointIndex
            {
                get;
                private set;
            }

            /// <summary>Gets the index of bottom border point.</summary>
            /// <value>The index of bottom border point.</value>
            public int BottomBorderPointIndex
            {
                get;
                private set;
            }

            /// <summary>Gets the index of top border point.</summary>
            /// <value>The index of top border point.</value>
            public int TopBorderPointIndex
            {
                get;
                private set;
            }
        }
    }
}